<?php
use app\admin\model\AuthRule as AuthRuleModel;
if (!AuthRuleModel::where('title', '商品管理')->count()) {
    $parent_id = AuthRuleModel::query()->create([
        'parent_id'    => 0,
        'title'        => '商品管理',
        'url'          => '#',
        'method'       => 'OPTIONS',
        'slug'         => 'goods'
    ]);
    $parent_id_1 = AuthRuleModel::query()->create([
        'parent_id'    => $parent_id->id,
        'title'        => '商品分类',
        'url'          => '/goods_category_index',
        'method'       => 'GET',
        'slug'         => 'goods.category_index'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '添加分类',
        'url'          => '/goods_category_create',
        'method'       => 'POST',
        'slug'         => 'goods.category_create'
    ]);

    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '编辑分类',
        'url'          => '/goods_category_edit',
        'method'       => 'POST',
        'slug'         => 'goods.category_edit'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '分类详情',
        'url'          => '/goods_category_detail',
        'method'       => 'GET',
        'slug'         => 'goods.category_detail'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '删除分类',
        'url'          => '/goods_category_delete',
        'method'       => 'POST',
        'slug'         => 'goods.category_delete'
    ]);
    $parent_id_2 = AuthRuleModel::query()->create([
        'parent_id'    => $parent_id->id,
        'title'        => '规格管理',
        'url'          => '/goods_rule_index',
        'method'       => 'GET',
        'slug'         => 'goods.rule_index'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_2->id,
        'title'        => '添加规格',
        'url'          => '/goods_category_create',
        'method'       => 'POST',
        'slug'         => 'goods.category_create'
    ]);

    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_2->id,
        'title'        => '编辑规格',
        'url'          => '/goods_rule_edit',
        'method'       => 'POST',
        'slug'         => 'goods.rule_edit'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_2->id,
        'title'        => '规格详情',
        'url'          => '/goods_rule_detail',
        'method'       => 'GET',
        'slug'         => 'goods.rule_detail'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_2->id,
        'title'        => '删除规格',
        'url'          => '/goods_rule_delete',
        'method'       => 'POST',
        'slug'         => 'goods.rule_delete'
    ]);
    $parent_id_3 = AuthRuleModel::query()->create([
        'parent_id'    => $parent_id->id,
        'title'        => '商品管理',
        'url'          => '/goods_index',
        'method'       => 'GET',
        'slug'         => 'goods.index'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_3->id,
        'title'        => '添加商品',
        'url'          => '/goods_create',
        'method'       => 'POST',
        'slug'         => 'goods.create'
    ]);

    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_3->id,
        'title'        => '编辑商品',
        'url'          => '/goods_edit',
        'method'       => 'POST',
        'slug'         => 'goods.edit'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_3->id,
        'title'        => '商品详情',
        'url'          => '/goods_detail',
        'method'       => 'GET',
        'slug'         => 'goods.detail'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_3->id,
        'title'        => '删除商品',
        'url'          => '/goods_delete',
        'method'       => 'POST',
        'slug'         => 'goods.delete'
    ]);
   
   
}

if (!AuthRuleModel::where('title', '订单管理')->count()) {
  $order =   AuthRuleModel::query()->create([
        'parent_id'    => 0,
        'title'        => '订单管理',
        'url'          => '#',
        'method'       => 'OPTIONS',
        'slug'         => 'order'
    ]);
   $order_1 =  AuthRuleModel::query()->create([
        'parent_id'    => $order->id,
        'title'        => '订单列表',
        'url'          => '/order_index',
        'method'       => 'GET',
        'slug'         => 'order.index'
    ]);
     AuthRuleModel::query()->create([
        'parent_id'    => $order_1->id,
        'title'        => '订单详情',
        'url'          => '/order_detail',
        'method'       => 'GET',
        'slug'         => 'order.detail'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $order_1->id,
        'title'        => '订单操作记录',
        'url'          => '/order_log',
        'method'       => 'GET',
        'slug'         => 'order.log'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $order_1->id,
        'title'        => '订单编辑',
        'url'          => '/order_edit',
        'method'       => 'POST',
        'slug'         => 'order.edit'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $order_1->id,
        'title'        => '订单发货',
        'url'          => '/order_deliver',
        'method'       => 'POST',
        'slug'         => 'order.deliver'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $order_1->id,
        'title'        => '退款通过',
        'url'          => '/order_refundyes',
        'method'       => 'POST',
        'slug'         => 'order.refund_y'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $order_1->id,
        'title'        => '订单导出',
        'url'          => '/order_export',
        'method'       => 'POST',
        'slug'         => 'order.export'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $order_1->id,
        'title'        => '退款拒绝',
        'url'          => '/order_refundno',
        'method'       => 'POST',
        'slug'         => 'order.refund_n'
    ]);
}

if (!AuthRuleModel::where('title', '数据统计')->count()) {
    $record =   AuthRuleModel::query()->create([
          'parent_id'    => 0,
          'title'        => '数据统计',
          'url'          => 'record',
          'method'       => 'GET',
          'slug'         => 'record'
      ]);
     $order_1 =  AuthRuleModel::query()->create([
          'parent_id'    => $record->id,
          'title'        => '订单',
          'url'          => '/record/chart_order',
          'method'       => 'GET',
          'slug'         => 'record.chart_order'
      ]);
      $order_2 =  AuthRuleModel::query()->create([
          'parent_id'    => $record->id,
          'title'        => '商品',
          'url'          => '/record/chart_goods',
          'method'       => 'GET',
          'slug'         => 'record.chart_goods'
      ]);
  }

if (!AuthRuleModel::where('title', '营销活动')->count()) {
    $market = AuthRuleModel::query()->create([
        'parent_id'    => 0,
        'title'        => '营销活动',
        'url'          => '#',
        'method'       => 'OPTIONS',
        'slug'         => 'marketing'
    ]);

   $coupon =  AuthRuleModel::query()->create([
        'parent_id'    => $market->id,
        'title'        => '优惠券',
        'url'          => '#',
        'method'       => 'OPTIONS',
        'slug'         => 'marketing.coupon'
    ]);

   $template =  AuthRuleModel::query()->create([
        'parent_id'    => $coupon->id,
        'title'        => '优惠券模板',
        'url'          => '/coupon_template_index',
        'method'       => 'GET',
        'slug'         => 'marketing.coupon_template'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $template->id,
        'title'        => '优惠券模板添加',
        'url'          => '/coupon_template_add',
        'method'       => 'POST',
        'slug'         => 'marketing.coupon_template_add'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $template->id,
        'title'        => '优惠券模板编辑',
        'url'          => '/coupon_template_edit',
        'method'       => 'POST',
        'slug'         => 'marketing.coupon_template_edit'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $template->id,
        'title'        => '优惠券模板删除',
        'url'          => '/coupon_template_del',
        'method'       => 'POST',
        'slug'         => 'marketing.coupon_template_del'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $template->id,
        'title'        => '优惠券发布',
        'url'          => '/coupon_template_issue',
        'method'       => 'POST',
        'slug'         => 'marketing.coupon_template_issue'
    ]);

    $coupon_index =  AuthRuleModel::query()->create([
        'parent_id'    => $coupon->id,
        'title'        => '优惠券列表',
        'url'          => '/coupon_index',
        'method'       => 'GET',
        'slug'         => 'marketing.coupon_index'
    ]);
  AuthRuleModel::query()->create([
        'parent_id'    => $coupon_index->id,
        'title'        => '优惠券领取记录',
        'url'          => '/coupon_log',
        'method'       => 'GET',
        'slug'         => 'marketing.coupon_log'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $coupon_index->id,
        'title'        => '优惠券删除',
        'url'          => '/coupon_delete',
        'method'       => 'POST',
        'slug'         => 'marketing.coupon_delete'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $coupon->id,
        'title'        => '用户优惠券',
        'url'          => '/coupon_user',
        'method'       => 'GET',
        'slug'         => 'marketing.coupon_user'
    ]);
}




